// pages/identifyDoc/register/regidter.js
var common = require('../../../config.js');
var util = require('../../../utils/util.js');
Page({
  data:{
    weChat:null
    },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
      var that =this;
      util.getOpenId(function(res){
        that.setData({
          weChat:res
        })
        console.log(that.data.weChat)
      })
      
  },
  onReady:function(){
    // 页面渲染完成
      
  },
  onShow:function(){
    // 页面显示

  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  formSubmit: function(e) {
    if(this.data.weChat){
        console.log('form发生了submit事件，携带数据为：',     e.detail.value)
      wx.request({
        url: common.registerUrl,
        data: {
          nickname:e.detail.value.nickname,
          number:e.detail.value.number,
          password:e.detail.value.password,
          email:e.detail.value.email,
          name:e.detail.value.name,
          weChat:this.data.weChat,
          deposit:0,
          identity:'普通会员'
        },
        method: 'post', 
        success: function(res){
          if(res.data.code == '1'){
            wx.showToast({
            title: '注册成功',
            icon: 'success',
            duration: 2000
            })
          }else if(res.data.code == '0'){
            console.log("注册失败")
          }else{
            console.log('code读取错误，code='+code);
          }

          wx.switchTab({
            url: '../../searchBook/searchBook',
          })
        },
        fail: function() {
          // fail
          console.log('submit fail');
        }
      })
      }
    
  },
  formReset: function() {
    console.log('form发生了reset事件')
  }
})